<?php
class util{
	function __construct(){
	}
	
	public static function sizeInKB($size){
		return round($size/1024,1);
	}
		
	public static function validateEmail($email){
		return ereg("^[-a-zA-Z0-9_.]+@([0-9A-Za-z][0-9A-Za-z-]+\.)+[A-Za-z]{2,5}$",$email);
	}
	public static function validateURL($url){
		return eregi("^http[s]{0,1}://[a-zA-Z0-9\.-]{1,}\.[a-zA-Z]{2,}.*$", $url);
	}
	public static function length($str){
		return mb_strlen($str,'utf-8');
	}
	public static function substr($str,$start,$length){
		return mb_substr($str, $start,$length,"utf-8");
	}
	public static function randID( $length = 20 )
	{
	    // 密码字符集，可任意添加你需要的字符
	    $chars = array('a', 'L', 'w', 'y','z', 'A', 'f', 'g', 'h', 
	    'i', 'j', 'S', 'l','m', 'n', 'o', 'p', 'q', 'r', 's', 
	    't', '3', '4', '5', 'B', 'b', 'c', 'd', 'e', 'C', 'D', 
	    'E', 'F', '7', 'G', 'H', 'J', 'K','M', 'N', 'O', 
	    'P', 'Q', 'R', 'T', 'x', 'U', 'V', 'W', 'X', 'Y','Z', 
	    '0', 'I', '1', '2', 'u', 'v', 'k', '6', '8', '9');
	
	    // 在 $chars 中随机取 $length 个数组元素键名
	    $keys = array_rand($chars, $length); 
	
	    $password = '';
	    for($i = 0; $i < $length; $i++)
	    {
	        // 将 $length 个数组元素连接成字符串
	        $password .= $chars[$keys[$i]];
	    }
	
	    return $password;
	}
	public static function date_int_to_string($dateint,$format='Y-m-d H:i:s'){
		return date($format,$dateint);
	}
}
?>